// pages/salestream/salestream.js
import { $wuxFilterBar } from '../../dist/wuxfilterbar'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 'tab1',
    current_scroll: 'tab1',

    page: '',
    Loading: false,
    isLogin: false,
    radioCheckVal: 0, //收益占比单选
    date: '2015-09-01', //收益占比时间段起始时间
    date2: '2018-01-24', //收益占比时间段终止时间

    items: [{
      type: 'filter',
      label: '分类筛选',
      selected:'111111111',
      value: 'filter',
      children: [{
        type: 'checkbox',
        label: '（多选）',
        value: 'query',
        children: [{
          label: '套餐',
          value: '1',
        },
        {
          label: '商品',
          value: '2',
        },
        {
          label: '食品',
          value: '3',
        },
        {
          label: '保健品',
          value: '4',
        },
        {
          label: '玩具',
          value: '5',
        },
        {
          label: '饮品',
          value: '6',
        },
        {
          label: '家居',
          value: '7',
        },
        {
          label: '电器',
          value: '8',
        },
        {
          label: '其他',
          value: '9',
        },
        ],
      }],
      groups: ['001', '002', '003'], //判断元素是否同组
    },],


  },

  handleChange({ detail }) {
    this.setData({
      current: detail.key
    });
  },

  handleChangeScroll({ detail }) {
    this.setData({
      current_scroll: detail.key
    });
  },

  // 收益占比时间段选择
  bindDateChange(e) {
    let that = this;
    console.log(e.detail.value)
    that.setData({
      date: e.detail.value,
      radioCheckVal: 0,
    })
    that.timeFn(that.data.arrayindex, that.data.date, that.data.date2)
  },
  bindDateChange2(e) {
    let that = this;
    that.setData({
      date2: e.detail.value,
      radioCheckVal: 0,
    })
    that.timeFn2(that.data.arrayindex, that.data.date, that.data.date2)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;

    this.$wuxFilterBar = $wuxFilterBar.init({
      items: this.data.items,
      onChange: (checkedItems, items) => {
        console.log(this, checkedItems, items)
        const params = {}
        checkedItems.forEach((n) => {
          if (n.value === 'filter') {
            console.log("选中的标题内容为：" + n.value);
            n.children.filter((n) => n.selected).forEach((n) => {
              if (n.value === 'query') {
                console.log("选中的具体内容为：" + n.value);
                const selected = n.children.filter((n) => n.checked).map((n) => n.value).join(' ')
                console.log("selected" + selected);
                params.query = selected;
                var arr = params.query;
                var newarr = arr.split(" ");
                console.log(typeof params.query);
                console.log("最终选中的内容为：" + newarr);
              }
            })
          }
        })
      },
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log("query="+this.data.query)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})